﻿using Antares.Common;
using Antares.VIEWMODELs;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Navigation;

// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237

namespace Antares.VIEWs
{
    /// <summary>
    /// A basic page that provides characteristics common to most applications.
    /// </summary>
    public sealed partial class ApprovePage
    {
        public ApprovePage()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
           // Navigator.Instance.HideApproveNotificator();

        }

        /// <summary>
        /// Preserves state associated with this page in case the application is suspended or the
        /// page is discarded from the navigation cache.  Values must conform to the serialization
        /// requirements of <see cref="SuspensionManager.SessionState"/>.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            //var projects = await ProjectMemberRepository.Instance.GetAllProjects(GlobalData.MyUserID);

            //if (projects.Any(projectInformationModel => projectInformationModel.IsConfirmed == false))
            //{
            //    Navigator.Instance.ShowApproveNotificator();
            //}

            //var tasks = await TaskRepository.Instance.GetAllTasksForUser(GlobalData.MyUserID);

            //if (tasks.Any(taskModel => taskModel.IsConfirmed == false))
            //{
            //    Navigator.Instance.ShowApproveNotificator();
            //}
        }

        private void FlipView_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            if (FlipView == null)
            {
                return;
            }

            if (FlipView.SelectedIndex == 0)
            {
                TaskTxt.Opacity = 1;
                ProjectTxt.Opacity = 0.4;
            }
            else
            {
                TaskTxt.Opacity = 0.4;
                ProjectTxt.Opacity = 1;
            }
        }

        private void TaskTxt_Tapped_1(object sender, TappedRoutedEventArgs e)
        {
            FlipView.SelectedIndex = 0;
        }

        private void ProjectTxt_Tapped_1(object sender, TappedRoutedEventArgs e)
        {
            FlipView.SelectedIndex = 1;
        }

        private void TaskGrid_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            ((ApproveViewModel)DataContext).SelectedTasks = TaskGrid.SelectedItems;
        }

        private void ProjectGrid_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            ((ApproveViewModel)DataContext).SelectedProjects = ProjectGrid.SelectedItems;
        }
    }
}
